package cn.enjoyedu.nettybasic.serializable.msgpack2;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import org.msgpack.MessagePack;

import java.util.List;

/*基于MessagePack的解码器，反序列化*/
public class MsgPackDecoder extends MessageToMessageDecoder<ByteBuf> {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
       final int i = msg.readableBytes();
       final byte[] arry=new byte[i];
       msg.getBytes(msg.readerIndex(),arry,0
       ,i);
        MessagePack messagePack=new MessagePack();
        out.add(messagePack.read(arry,User.class));

    }
}
